<!DOCTYPE html>
<html class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
	      content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./js/jquery.min.js"></script>
	<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/adminzoneview.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/userinfoview.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"/></script>
	<script type="text/javascript" src="./js/abkj/match/api/judgmentdata.js"/></script>


	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/matchzoneview.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/schedule.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"></script>

	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"/></script>
	<script src="./js/vue.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="./js/html5.min.js"></script>
	<script src="./js/respond.min.js"></script>
	<![endif]--></head>

<body>
<div class="layui-fluid" id="app">
	<div class="layui-row">
		<form class="layui-form">
			<div class="layui-form-item">
				<label for="review" class="layui-form-label">
					<span class="x-red">*</span>赛项</label>
				<div class="layui-input-inline">
					<select id="saixiang" name="project" lay-filter="project">
                      <option value="">请选择</option>
												<option v-for="item in list1" :value="item.id">{{item.theme}}</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="division" class="layui-form-label">
					<span class="x-red">*</span>赛区</label>
				<div class="layui-input-inline">
					<select id="saiqu" name="project">
						<option value="">请选择</option>
							<option v-for="item in list3" :value="item.id">{{item.zoneName}}</option>

					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="schedule" class="layui-form-label">
					<span class="x-red">*</span>赛程</label>
				<div class="layui-input-inline">
					<select id="saicheng" name="project">
						<option value="">请选择</option>
							<option v-for="item in list2" :value="item.id">{{item.scheduleName}}</option>

					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="group" class="layui-form-label">
					<span class="x-red">*</span>组别</label>
				<div class="layui-input-inline">
					<select id="zubie" name="project">
						<option value="">请选择</option>
							<option v-for="item in list5" :value="item.id">{{item.gradeName}}</option>

					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="review" class="layui-form-label"></label>
				<button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
			</div>
		</form>
	</div>
</div>
<script>
var app=new Vue({
	    el:'#app',
			data:{
				   list1:[],
					 list2:[],
					 list3:[],
					 list5:[]
			},
			methods:{

			}
})
function request(strParame) {
	var args = new Object( );
	var query = location.search.substring(1);

	var pairs = query.split("&"); // Break at ampersand
	for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');
	if (pos == -1) continue;
	var argname = pairs[i].substring(0,pos);
	var value = pairs[i].substring(pos+1);
	value = decodeURIComponent(value);
	args[argname] = value;
	}
	return args[strParame];
}
	var form
layui.use(['form', 'layer'],
	function () {
		$ = layui.jquery
 form = layui.form,


		//自定义验证规则

	 form.on('select(project)', function(data){ 
		 var querydata={
			 eq:{
				 matchId:document.getElementById('saixiang').value
			 }
		 } 
		 SchedulequeryList(querydata, function (data) {
				 // alert(JSON.stringify(data))
				 app.list2=data
				 // alert(JSON.stringify(app.list2))
				 var data1
				 getMatchEntiry(document.getElementById("saixiang").value,function(data){
					   var data2=data
					   data1=data.zoneList
						ZonequeryList({}, function (data) {
							  // alert(JSON.stringify(data))
							  var string1=data1.toString()
								var list2=[]
								for (i=0;i<data.length;i++){
									   var idstring=data[i].id
										 idstring=idstring.toString()
										 if (string1.indexOf(idstring)>-1){
											 list2.push(data[i])
										 }
								}
								// alert(JSON.stringify(list2))
								app.list3=list2
								GradequeryList({}, function (data) {

									setTimeout(function(){
										form.render()
									},1000)

									var gradeList=data2.gradeList
									var list5=[]
									gradeList=gradeList.toString()
									for (i=0;i<data.length;i++){
										  var idstring=data[i].id
											idstring=idstring.toString()
											if (gradeList.indexOf(idstring)>-1){
												list5.push(data[i])
											}
									}
									// alert(JSON.stringify(list5))
									app.list5=list5

									// alert(JSON.stringify(gradeList))
								})

						})

				 })


		 })
	                        });
		form.verify({
			nikename: function (value) {
				if (value.length < 5) {
					return '昵称至少得5个字符啊'
				}
			},
			pass: [/(.+){6,12}$/, '密码必须6到12位'],
			repass: function (value) {
				if ($('#L_pass').val() != $('#L_repass').val()) {
					return '两次密码不一致'
				}
			}
		})

		//监听提交
		form.on('submit(add)',
			function (data) {
				if (!request("editid")){
					  //添加
						obj1={
							matchId:document.getElementById("saixiang").value,//Integer 赛程ID
							scheduleId:document.getElementById("saicheng").value,//Integer 赛程ID
							zoneId:document.getElementById("saiqu").value,//Integer 赛区ID
							gradeId:document.getElementById("zubie").value,//Integer 组别ID
							userId:localStorage.myuserid,//Long 用户ID
							matchName:document.getElementById("saixiang").options[document.getElementById("saixiang").selectedIndex].text,//String 赛程名称
							scheduleName:document.getElementById("saicheng").options[document.getElementById("saicheng").selectedIndex].text,//String 赛项名称
							zoneName:document.getElementById("saiqu").options[document.getElementById("saiqu").selectedIndex].text,//String 赛区名称
							gradeName:document.getElementById("zubie").options[document.getElementById("zubie").selectedIndex].text,//String 组别名称
						}
						JudgmentDataaddObj(obj1, function (data) {

						})

				}
				else {
					obj1={
						matchId:document.getElementById("saixiang").value,//Integer 赛程ID
						scheduleId:document.getElementById("saicheng").value,//Integer 赛程ID
						zoneId:document.getElementById("saiqu").value,//Integer 赛区ID
						gradeId:document.getElementById("zubie").value,//Integer 组别ID
						userId:localStorage.myuserid,//Long 用户ID
						matchName:document.getElementById("saixiang").options[document.getElementById("saixiang").selectedIndex].text,//String 赛程名称
						scheduleName:document.getElementById("saicheng").options[document.getElementById("saicheng").selectedIndex].text,//String 赛项名称
						zoneName:document.getElementById("saiqu").options[document.getElementById("saiqu").selectedIndex].text,//String 赛区名称
						gradeName:document.getElementById("zubie").options[document.getElementById("zubie").selectedIndex].text,//String 组别名称
						id:request("editid")
					}
					JudgmentDataupdateById(obj1, function (data) {

					})
				}
				//发异步，把数据提交给php
				layer.alert("编辑完成！", {
						icon: 6
					},
					function () {
						// 获得frame索引
						var index = parent.layer.getFrameIndex(window.name)
						//关闭当前frame
						parent.layer.close(index)

						// 可以对父窗口进行刷新
						xadmin.father_reload()
					})
				return false
			})

	})
function initdata(){
	   if (!request("editid")){
			 //初始数据
			 MatchZoneViewqueryList({}, function (data) {
				  // alert(JSON.stringify(data))
					// app.list1=data
					var records=data
 				 var list=[]
 				 var list1=[]

 				 for (i=0;i<records.length;i++){
 					   var string1=list1.toString()
 						 if (string1.indexOf(records[i].id)==-1){
 							 list1.push(records[i].id)
 							 list.push(records[i])
 						 }
 				 }
 				 list=list.reverse()
				 app.list1=list

			 })
		 }
		 else {

			 var param = {
 				eq:{
 					userId:localStorage.myuserid
 				}
 			}
 			JudgmentDataqueryList(param,function(data){
				 // alert(JSON.stringify(data))
				 var tlist=[]
					for (i=0;i<data.length;i++){
						  if (data[i].id==request("editid")){
								tlist=data[i]
								break
							}
					}
					// alert(JSON.stringify(tlist))
				 MatchZoneViewqueryList({}, function (data) {
						// alert(JSON.stringify(data))
						// app.list1=data

						var records=data
					 var list=[]
					 var list1=[]

					 for (i=0;i<records.length;i++){
							 var string1=list1.toString()
							 if (string1.indexOf(records[i].id)==-1){
								 list1.push(records[i].id)
								 list.push(records[i])
							 }
					 }
					 list=list.reverse()
					 app.list1=list
					 var querydata={
						 eq:{
							 matchId:tlist.matchId
						 }
					 } 
					 SchedulequeryList(querydata, function (data) {
							 // alert(JSON.stringify(data))
							 app.list2=data
							 // alert(JSON.stringify(app.list2))
							 var data1

							 getMatchEntiry(tlist.matchId,function(data){
									 var data2=data
									 data1=data.zoneList
									ZonequeryList({}, function (data) {
											// alert(JSON.stringify(data))
											var string1=data1.toString()
											var list2=[]
											for (i=0;i<data.length;i++){
													 var idstring=data[i].id
													 idstring=idstring.toString()
													 if (string1.indexOf(idstring)>-1){
														 list2.push(data[i])
													 }
											}
											// alert(JSON.stringify(list2))
											app.list3=list2
											GradequeryList({}, function (data) {



												var gradeList=data2.gradeList
												var list5=[]
												gradeList=gradeList.toString()
												for (i=0;i<data.length;i++){
														var idstring=data[i].id
														idstring=idstring.toString()
														if (gradeList.indexOf(idstring)>-1){
															list5.push(data[i])
														}
												}
												// alert(JSON.stringify(list5))
												app.list5=list5

												// alert(JSON.stringify(gradeList))
												//开始选中数据


												setTimeout(function(){
													// form.render()
													// alert(tlist.matchId)
														// alert(JSON.stringify(tlist))
 												var saixiang=document.getElementById("saixiang")
 												// alert(saixiang.options.length)
 												for (i=0;i<saixiang.options.length;i++){
 													  // alert(saixiang.options[i].value)
 													  if (saixiang.options[i].value==tlist.matchId){
 															saixiang.options[i].selected=true
 															// alert(1)
 															break
 														}
 												}
												var saiqu=document.getElementById("saiqu")
												for (i=0;i<saiqu.options.length;i++){
														// alert(saixiang.options[i].value)
														if (saiqu.options[i].value==tlist.zoneId){
															saiqu.options[i].selected=true
															// alert(1)
															break
														}
												}
												var saicheng=document.getElementById("saicheng")
												for (i=0;i<saicheng.options.length;i++){
														// alert(saixiang.options[i].value)
														if (saicheng.options[i].value==tlist.scheduleId){
															saicheng.options[i].selected=true
															// alert(1)
															break
														}
												}
												var zubie=document.getElementById("zubie")
												for (i=0;i<zubie.options.length;i++){
														// alert(saixiang.options[i].value)
														if (zubie.options[i].value==tlist.gradeId){
															zubie.options[i].selected=true
															// alert(1)
															break
														}
												}

												 form.render()
												},1000)
											})

									})
										})

							 })

				 })
			 })

		 }
}
initdata()
layui.use(['form'], function() {
        

        });

</script>
<script>var _hmt = _hmt || [];
(function () {
	var hm = document.createElement("script")
	hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"
	var s = document.getElementsByTagName("script")[0]
	s.parentNode.insertBefore(hm, s)
})()</script>
</body>

</html>
